<?php

namespace app\api\controller\Start;
use app\api\controller\Common;
use app\api\Logic\Article\ArticleLogic;
use app\api\Logic\CommonLogic;
use app\api\Logic\Index\IndexLogic;

/**
 * 首页
 */
class Index extends Common
{
    protected $noNeedLogin = ['*'];

    protected $interactLogic;
    protected $commonLogic;
    protected $indexLogic;

    public function _initialize()
    {
        parent::_initialize();

        $this->indexLogic = new IndexLogic();
        $this->articleLogic = new ArticleLogic();
        $this->commonLogic = new CommonLogic();
    }

    /**
     * 获取首页轮播图
     *
     */
    public function getIndexBanner()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);
            $data = $this->indexLogic->getBanner($param);
            $this->success('查询成功',$data);
        }
        $this->error('请求错误');
    }

    /**
     * 获取首页推荐瓷片区及视频数据
     *
     */
    public function getModuleAndVideo()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);
            $module = $this->indexLogic->getModuleData($param);
            $video = $this->indexLogic->getVideoData($param);
            $this->success('查询成功',['module'=>$module,'video'=>$video]);
        }
        $this->error('请求错误');
    }

    /**
     * 获取首页推荐数据列表
     *
     */
    public function getRecommendList()
    {
        if ($this->request->isPost()) {
            $param = $this->request->param();
            //验证数据
            $param = $this->verifyData($param);
            // 互动讨论
            $interact = $this->indexLogic->getRecommendInteract($param);
            $articleLogic = new ArticleLogic();
            // 普通文章
            $article = $articleLogic->getArticleList($param['shop_id'],$param['user_id'],$param['page'],$param['page_size'],[1,2,3],0,3);
            // 萌娃圈
            $video = $articleLogic->getArticleList($param['shop_id'],$param['user_id'],$param['page'],$param['page_size'],4,0,3);
            $this->success('查询成功',['interact'=>$interact,'article'=>$article,'video'=>$video]);
        }
        $this->error('请求错误');
    }

}
